package models

import (
	"database/sql"
	"github.com/jinzhu/gorm"

)

type Buildings struct {
	gorm.Model
	BuildingId       int            `json:"building_id"`
	Uid              string         `json:"uid"`
	BuildingName     string         `json:"building_name"`
	BuildingNamePath string `json:"building_name_path"`
	BuildingCallNum  string         `json:"building_call_num"`
	BuildingGps      sql.NullString `json:"building_gps"`
	ZoneId           sql.NullInt64  `json:"zone_id"`
	GateIp           string         `json:"gate_ip"`
	GatewayIp        string         `json:"gateway_ip"`
	SubnetMask       string         `json:"subnet_mask"`
	GateDns          string         `json:"gate_dns"`
	Vpn              string         `json:"vpn"`
	VpnAccount       string         `json:"vpn_account"`
	VpnPwd           string         `json:"vpn_pwd"`
	CameraFront      string         `json:"camera_front"`
	CameraFrontPort  int            `json:"camera_front_port"`
	CameraFloor      string         `json:"camera_floor"`
	CameraFloorPort  int            `json:"camera_floor_port"`
	CameraFloorDelay int            `json:"camera_floor_delay"`
	BuildingNo       string         `json:"building_no"`
	CreatedAt        sql.NullInt64  `json:"created_at"`
	UpdatedAt        sql.NullInt64  `json:"updated_at"`
	DeletedAt        sql.NullInt64  `json:"deleted_at"`
}

//获取卡信息
func GetCommunityInfo(BuildingId int) (string, error) {
	var buildings Buildings
	err := db.Select("building_name_path").Where("building_id = ? ", BuildingId).First(&buildings).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return buildings.BuildingNamePath, err
	}
	return buildings.BuildingNamePath, nil
}